package algorithm.leetcode.medium;

/*
 给定一个二叉树的根节点 root ，返回它的 中序 遍历。
 */

import java.util.ArrayList;
import java.util.List;

/**
 * @author jack.wu
 * @version 1.0
 * @date 2020/11/24
 */
public class Question94 {

    public static void main(String[] args) {

    }

    public List<Integer> inorderTraversal(TreeNode root) {
        List<Integer> res = new ArrayList<>(10);
        midTraversal(root, res);
        return res;
    }

    private void midTraversal(TreeNode root, List<Integer> res) {
        if (root == null) {
            return;
        }
        midTraversal(root.left, res);
        res.add(root.val);
        midTraversal(root.right, res);
    }


    private static class TreeNode {
        int val;
        TreeNode left;
        TreeNode right;

        TreeNode() {
        }

        TreeNode(int val) {
            this.val = val;
        }

        TreeNode(int val, TreeNode left, TreeNode right) {
            this.val = val;
            this.left = left;
            this.right = right;
        }
    }
}
